import javax.security.auth.kerberos.KerberosCredMessage;

public class lk6352{
    public long dividePlayers(int[] skill) {
        int n=skill.length;
        int all=0,max=0;
        int min=1000;
        for(int i=0;i<n;i++){
            all+=skill[i];
            if(skill[i]>max){
                max=skill[i];
            }
            if(skill[i]<min){
                min=skill[i];
            }
        }
        if((all*2)%n!=0){
            return -1;
        }
        int ave=all*2/n;
        if((max+min)>ave){
            return -1;
        }
        int pan=0;
        for(int i=0;i<n-1;i++){
            if(skill[i]!=0)
            for(int j=i+1;j<n;j++){
                pan=skill[i]+skill[j];
                if(pan==ave){
                    skill[i]=0;
                    skill[j]=0;
                    break;
                }
                if(j==n-1){
                    return -1;
                }
            }
        }
        int end=0;
        for(int i=0;i<n;i++){
            end+=(ave-skill[i])*skill[i];
        }
        return end/2;
    }
}